__author__ = 'Jerry Liu'
from socket import *
from time import ctime

HOST = input('Please input your host:')   #注意主机名不能随便打，我小白。。。发现只有127.XX.XX.XX在本机可以正常使用
PORT = int(input('Please input your port:'))
BUFSIZ = 1024
ADDR = (HOST, PORT)

tcpSerSork = socket(AF_INET, SOCK_STREAM)
tcpSerSork.bind(ADDR)
tcpSerSork.listen(5)

while True:
    print ('wait for connection...')
    tcpCliSork, addr = tcpSerSork.accept()
    print ('... connected from:', addr)

    while True:
        data = tcpCliSork.recv(BUFSIZ)
        if not data:
            break
        tcpCliSork.send('[%s] %s' % (ctime(), data))
    tcpCliSork.close()
tcpSerSork.close()